/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package telas;

import br.edu.GenericDAO;
import javax.swing.JOptionPane;
import usuario.Usuario;
import usuario.UsuarioDAO;

/**
 *
 * @author Max Weber
 */
public class O5TelaAlterarSenha extends javax.swing.JDialog {

    /**
     * Creates new form O5AlterarSenha
     */
    Usuario usuario;
    boolean castrado;
    public O5TelaAlterarSenha() {
        initComponents();
        setModal(true);
    }
    public O5TelaAlterarSenha(Usuario usuarios){
        initComponents();
        setModal(true);
        this.usuario= usuarios;
        tfNome.setText(usuarios.getNome_usuario());
       
        
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jPanel2 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        tfNovaSenha = new javax.swing.JPasswordField();
        jLabel3 = new javax.swing.JLabel();
        tfConfirmarSenha = new javax.swing.JPasswordField();
        jPanel8 = new javax.swing.JPanel();
        btCancelar = new javax.swing.JLabel();
        jPanel9 = new javax.swing.JPanel();
        btAlterar = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        tfNome = new javax.swing.JTextField();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("SISVATEC - Sistema de Vacinação");
        setResizable(false);
        getContentPane().setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        jPanel1.setBackground(new java.awt.Color(255, 255, 255));
        jPanel1.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        jPanel2.setBackground(new java.awt.Color(0, 114, 180));
        jPanel2.setLayout(new java.awt.GridLayout(1, 0));

        jLabel1.setFont(new java.awt.Font("Arial", 1, 16)); // NOI18N
        jLabel1.setForeground(new java.awt.Color(255, 255, 255));
        jLabel1.setText("   Alterar senha");
        jPanel2.add(jLabel1);

        jPanel1.add(jPanel2, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 0, 400, 30));

        jLabel2.setFont(new java.awt.Font("Arial", 0, 18)); // NOI18N
        jLabel2.setText("Nova senha:");
        jPanel1.add(jLabel2, new org.netbeans.lib.awtextra.AbsoluteConstraints(130, 110, -1, -1));

        tfNovaSenha.setFont(new java.awt.Font("Arial", 0, 16)); // NOI18N
        tfNovaSenha.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 114, 180), 2));
        jPanel1.add(tfNovaSenha, new org.netbeans.lib.awtextra.AbsoluteConstraints(130, 140, 220, 30));

        jLabel3.setFont(new java.awt.Font("Arial", 0, 18)); // NOI18N
        jLabel3.setText("Confirmar senha:");
        jPanel1.add(jLabel3, new org.netbeans.lib.awtextra.AbsoluteConstraints(130, 180, -1, -1));

        tfConfirmarSenha.setFont(new java.awt.Font("Arial", 0, 16)); // NOI18N
        tfConfirmarSenha.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 114, 180), 2));
        jPanel1.add(tfConfirmarSenha, new org.netbeans.lib.awtextra.AbsoluteConstraints(130, 210, 220, 30));

        jPanel8.setBackground(new java.awt.Color(10, 66, 108));
        jPanel8.setLayout(new java.awt.GridBagLayout());

        btCancelar.setFont(new java.awt.Font("Arial", 1, 16)); // NOI18N
        btCancelar.setForeground(new java.awt.Color(255, 255, 255));
        btCancelar.setText("Cancelar");
        btCancelar.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                btCancelarMouseClicked(evt);
            }
        });
        jPanel8.add(btCancelar, new java.awt.GridBagConstraints());

        jPanel1.add(jPanel8, new org.netbeans.lib.awtextra.AbsoluteConstraints(120, 270, 120, 30));

        jPanel9.setBackground(new java.awt.Color(10, 66, 108));
        jPanel9.setLayout(new java.awt.GridBagLayout());

        btAlterar.setFont(new java.awt.Font("Arial", 1, 16)); // NOI18N
        btAlterar.setForeground(new java.awt.Color(255, 255, 255));
        btAlterar.setText("Alterar");
        btAlterar.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                btAlterarMouseClicked(evt);
            }
        });
        jPanel9.add(btAlterar, new java.awt.GridBagConstraints());

        jPanel1.add(jPanel9, new org.netbeans.lib.awtextra.AbsoluteConstraints(260, 270, 120, 30));

        jLabel4.setIcon(new javax.swing.ImageIcon(getClass().getResource("/img/cadeado.png"))); // NOI18N
        jPanel1.add(jLabel4, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 130, -1, -1));

        jLabel5.setFont(new java.awt.Font("Verdana", 0, 12)); // NOI18N
        jLabel5.setText("Usuário:");
        jPanel1.add(jLabel5, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 40, -1, -1));

        tfNome.setFont(new java.awt.Font("Arial", 0, 16)); // NOI18N
        tfNome.setBorder(null);
        tfNome.setEnabled(false);
        jPanel1.add(tfNome, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 60, 370, 30));

        getContentPane().add(jPanel1, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 0, 400, 320));

        pack();
        setLocationRelativeTo(null);
    }// </editor-fold>//GEN-END:initComponents

    private void btCancelarMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_btCancelarMouseClicked
        // TODO add your handling code here:
        dispose();
    }//GEN-LAST:event_btCancelarMouseClicked

    private void btAlterarMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_btAlterarMouseClicked
        // TODO add your handling code here:
        
        
        if(castrado){
        usuario = new Usuario();
        }
      
        if(tfNovaSenha.getText().equals(tfConfirmarSenha.getText())){
            usuario.setSenha(tfNovaSenha.getText());
            
            UsuarioDAO dao = new UsuarioDAO();
            dao.atualizar(usuario);
            JOptionPane.showMessageDialog(rootPane, "Senha alterada com sucesso!");
            
            limparCampos();
            dispose();
            
        } else {
            JOptionPane.showMessageDialog(rootPane, "As senhas não conferem!");
        }
        
        
        
    }//GEN-LAST:event_btAlterarMouseClicked

    public void limparCampos(){
        
        tfNome.setText("");
        tfNovaSenha.setText("");
        tfConfirmarSenha.setText("");
    }
    
    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(O5TelaAlterarSenha.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(O5TelaAlterarSenha.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(O5TelaAlterarSenha.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(O5TelaAlterarSenha.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new O5TelaAlterarSenha().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel btAlterar;
    private javax.swing.JLabel btCancelar;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel8;
    private javax.swing.JPanel jPanel9;
    private javax.swing.JPasswordField tfConfirmarSenha;
    private javax.swing.JTextField tfNome;
    private javax.swing.JPasswordField tfNovaSenha;
    // End of variables declaration//GEN-END:variables
}
